// Copyright 2007-2010 Comdiv (F. Sadykov) - http://code.google.com/u/fagim.sadykov/
// Supported by Media Technology LTD 
//  
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
// MODIFICATIONS HAVE BEEN MADE TO THIS FILE
using System;
using System.Web.Mvc;
using System.Web.Routing;
using MvcContrib.Comdiv.Layers;
using MvcContrib.Comdiv.ViewEngines.Brail;
using MvcContrib.ViewFactories;
using NUnit.Framework;
using Rhino.Mocks;

namespace Comdiv.Brail.Tests{
    [TestFixture]
    [Category("BrailViewEngine")]
    public class BrailViewFactoryTester{
        #region Setup/Teardown

        [SetUp]
        public void SetUp(){
            _mocks = new MockRepository();
            var httpContext = new TestHttpContext();
            var requestContext = new RequestContext(httpContext, new RouteData());
            var controller = _mocks.StrictMock<ControllerBase>();
            _mocks.Replay(controller);

            var viewEngine = new BooViewEngine{
                                                  //ViewSourceLoader = new FileSystemViewSourceLoader(VIEW_ROOT_DIRECTORY),
                                                  //Factory = new BrailViewFactory().configureLayers("brail",true,"MvcContrib_Existed_Tests")
                                                 //,
                                                  Options = new BooViewEngineOptions(),
                                                  //SelfResolveRoot = "~/MvcContrib_Existed_Tests/Views",
                                              };

            _viewEngine = new BrailViewFactory(viewEngine).configureLayers("brail", true, "MvcContrib_Existed_Tests");
            viewEngine.Initialize();
            _mocks.ReplayAll();
        }

        #endregion

        private IViewEngine _viewEngine;
        private MockRepository _mocks;

        [Test]
        public void Can_Create_Default_ViewFactory(){
            var viewFactory = new BrailViewFactory();
            Assert.IsNotNull(viewFactory.ViewEngine);
        }

        [Test]
        public void Can_Create_View(){
            var routeData = new RouteData();
            routeData.Values.Add("controller", "home");
            ViewEngineResult result = _viewEngine.FindView(new ControllerContext{RouteData = routeData}, "view", null,
                                                           false);
            Assert.IsNotNull(result.View);
        }

        [Test]
        [ExpectedException(typeof (ArgumentNullException))]
        public void Depends_On_BooViewEngine(){
            new BrailViewFactory(null);
        }

        [Test]
        public void ReleaseView_should_not_throw(){
            _viewEngine.ReleaseView(null, null);
        }
    }
}